package org.bigjava.mapper;


import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.bigjava.bean.Compliant;
import org.bigjava.bean.Wuye;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository("compliantMapper")
public interface CompliantMapper {

    //根据id处理投诉信息
    @Update("update compliant set status=2 where id=#{id}")
    public int compliantChuLi(int id);

    //根据物业公司或投诉人查询投诉信息
    @Select("<script>"+
            "select * from compliant where jsc=1"+
            "<if test='w_id>0'> and w_id = #{w_id} </if>" +
            "<if test='tsr!=null'>and tsr = #{tsr}</if>"+
            "</script>")
    @Results({
            @Result(property ="wuye",column = "w_id",javaType = Wuye.class,
                    one = @One(select="org.bigjava.mapper.WuyeMapper.wuYeId",fetchType = FetchType.LAZY))
    })
    public List<Compliant> compliantSouSuo(int w_id, String tsr);
    //投诉总数
    @Select("select count(*) from compliant where jsc=1")
    public int compliantZong();

    //根据id假删除
    @Update("update compliant set jsc=0 where id=#{id}")
    public int compliantShanChu(int id);

    //分页查询投诉信息
    @Select("select * from compliant where jsc=1 limit #{offset},#{length}")
    @Results({
            @Result(property ="wuye",column = "w_id",javaType = Wuye.class,
                    one = @One(select="org.bigjava.mapper.WuyeMapper.wuYeId",fetchType = FetchType.LAZY))
    })
    public List<Compliant> compliantFenYe(int offset , int length);

    //投诉
    @Insert("insert into compliant(tsr,content,phone,tssj,w_id)" +
            " values (#{tsr},#{content},#{phone},#{tssj},#{w_id})")
    public int compliantAdd(Compliant compliant);

}
